package com.dt76.smallloanbackendservice.service.xm.impl;

import com.dt76.smallloanbackendservice.mapper.xm.BeforeOrderMapper;
import com.dt76.smallloanbackendservice.pojo.xm.BeforeOrder;
import com.dt76.smallloanbackendservice.pojo.xm.BeforeOrderQuery;
import com.dt76.smallloanbackendservice.service.xm.BeforeOrderService;
import com.dt76.smallloanbackendservice.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BeforeOrderServiceImpl implements BeforeOrderService {

    @Autowired
    private BeforeOrderMapper beforeOrderMapper;

    @Override
    public Page getAllOrderByPage(Integer currentPageNo, BeforeOrderQuery beforeOrderQuery) {
        Page page = new Page();
        page.setPageIndex(currentPageNo);
        String startTime = "";
        String endTime = "";
        if (beforeOrderQuery.getQueryStartTime() != null && beforeOrderQuery.getQueryEndTime() != null) {
            startTime = beforeOrderQuery.getQueryStartTime();
            System.out.println(startTime);
            endTime = beforeOrderQuery.getQueryEndTime();
            System.out.println(endTime);
        }
        page.setTotalCount(beforeOrderMapper.qryConditionCount(beforeOrderQuery.getQueryName(), beforeOrderQuery.getQueryPhone(), startTime, endTime, beforeOrderQuery.getQueryType(), beforeOrderQuery.getQueryBoType(), beforeOrderQuery.getQueryBoTypeList()));
        page.setRows(beforeOrderMapper.qryConditionPageAll((page.getPageIndex() - 1) * page.getPageSize(), page.getPageSize(),
                beforeOrderQuery.getQueryName(), beforeOrderQuery.getQueryPhone(), startTime, endTime, beforeOrderQuery.getQueryType(), beforeOrderQuery.getQueryBoType(), beforeOrderQuery.getQueryBoTypeList()));
        return page;
    }

    @Override
    public Page getAllOrderByPage2(Integer currentPageNo, BeforeOrderQuery beforeOrderQuery) {
        Page page = new Page();
        page.setPageIndex(currentPageNo);
        String startTime = "";
        String endTime = "";
        if (beforeOrderQuery.getQueryStartTime() != null && beforeOrderQuery.getQueryEndTime() != null) {
            startTime = beforeOrderQuery.getQueryStartTime();
            System.out.println(startTime);
            endTime = beforeOrderQuery.getQueryEndTime();
            System.out.println(endTime);
        }
        page.setTotalCount(beforeOrderMapper.qryConditionCount(beforeOrderQuery.getQueryName(), beforeOrderQuery.getQueryPhone(), startTime, endTime, beforeOrderQuery.getQueryType(), beforeOrderQuery.getQueryBoType(), beforeOrderQuery.getQueryBoTypeList()));
        page.setRows(beforeOrderMapper.qryConditionPageAll2((page.getPageIndex() - 1) * page.getPageSize(), page.getPageSize(),
                beforeOrderQuery.getQueryName(), beforeOrderQuery.getQueryPhone(), startTime, endTime, beforeOrderQuery.getQueryType(), beforeOrderQuery.getQueryBoType(), beforeOrderQuery.getQueryBoTypeList()));
        return page;
    }

    @Override
    public BeforeOrder qryByID(int id) {
        return beforeOrderMapper.qryByID(id);
    }

    @Override
    public int modifyBeforeOrderType(BeforeOrder beforeOrder) {
        return beforeOrderMapper.modifyBeforeOrderType(beforeOrder);
    }



}
